Imports Pacientes
Imports System.Data.SqlClient

Public Class frmActDatosPacienteCORREGIDO


    Private TipoDoc As TipoDocumento = Nothing
    Private Barrio As Barrio = Nothing
    Private Loc As Localidad = Nothing
    Private OS As ObraSocial = Nothing
    Private Estado As Estado = Nothing
    Private TPac As TipoPaciente = Nothing
    Private paci As Paciente = Nothing
    Private TT As TipoTelefono = Nothing
    Private objLoc As Localidad = Nothing

    Private idLoc As Integer = 0
    Private DescLoc As String = ""

    Private IdBar As Integer = 0
    Private DescBar As String = ""

    Private IdEst As Integer = 0
    Private DescEst As String = ""

    Private IdObraSoc As Integer = 0
    Private DescOS As String = ""
    Private IdTipoPac As Integer = 0
    Private DescTPac As String = ""

    Private nrodoc As String = ""
    Private idTD As Integer = 0
    Private DescTD As String = ""

    Private IdTipoTel As Integer = 0
    Private DescTT As String = ""
    
    Public Property Paciente() As Paciente
        Get
            Return paci
        End Get
        Set(ByVal value As Paciente)
            paci = value
        End Set
    End Property
    Private Sub cargarComboTipoDoc()
        Dim datos As DataSet = Nothing
        TipoDoc = New TipoDocumento()
        datos = TipoDoc.BuscarDatos(conexion)
        Me.cboTipoDoc.DataSource = datos.Tables(0)
        Me.cboTipoDoc.DisplayMember = "descrip"
        Me.cboTipoDoc.ValueMember = "idtipodoc"

        'busca por letra el indice del combo
        Dim index As Integer = 0
        index = Me.cboTipoDoc.FindString(Me.cboTipoDoc.Text)
        Me.cboTipoDoc.SelectedIndex = index


    End Sub
    Private Sub ComboBarrio()

        Dim objLoc As Localidad = Nothing
        objLoc = New Localidad()
        DescLoc = cboLoc.Text
        With Me.objLoc
            If objLoc.BuscarId(DescLoc, conexion) Then
                idLoc = objLoc.Identificador()
            End If
        End With

        Dim datos As DataSet = Nothing
        Barrio = New Barrio()
        datos = Barrio.BuscarDatosxLoc(idLoc, conexion)
        Me.cboBarrio.DataSource = datos.Tables(0)
        Me.cboBarrio.DisplayMember = "descrip"
        Me.cboBarrio.ValueMember = "idbarrio"

        Dim index As Integer = 0
        index = Me.cboBarrio.FindString(Me.cboBarrio.Text)
        Me.cboBarrio.SelectedIndex = index

        cboBarrio.Text = ""
    End Sub
    Private Sub ComboLoc()
        Dim datos As DataSet = Nothing
        Loc = New Localidad()
        datos = Loc.BuscarDatos(conexion)
        Me.cboLoc.DataSource = datos.Tables(0)
        Me.cboLoc.DisplayMember = "descrip"
        Me.cboLoc.ValueMember = "idLoc"

        Dim index As Integer = 0
        index = Me.cboLoc.FindString(Me.cboLoc.Text)
        Me.cboLoc.SelectedIndex = index

        cboLoc.Text = ""
    End Sub
    Private Sub ComboObraSoc()
        Dim datos As DataSet = Nothing
        OS = New ObraSocial()
        datos = OS.BuscarDatos(conexion)
        Me.cboObraSoc.DataSource = datos.Tables(0)
        Me.cboObraSoc.DisplayMember = "descrip"
        Me.cboObraSoc.ValueMember = "idobrasocial"

        Dim index As Integer = 0
        index = Me.cboObraSoc.FindString(Me.cboObraSoc.Text)
        Me.cboObraSoc.SelectedIndex = index

        cboObraSoc.Text = ""
    End Sub
    Private Sub ComboTipoPac()
        Dim datos As DataSet = Nothing
        TPac = New TipoPaciente()
        datos = TPac.BuscarDatos(conexion)
        Me.cboTipoPac.DataSource = datos.Tables(0)
        Me.cboTipoPac.DisplayMember = "descrip"
        Me.cboTipoPac.ValueMember = "idtipopaciente"

        Dim index As Integer = 0
        index = Me.cboTipoPac.FindString(Me.cboTipoPac.Text)
        Me.cboTipoPac.SelectedIndex = index

        cboTipoPac.Text = ""
    End Sub
    Private Sub ComboEstado()
        Dim datos As DataSet = Nothing
        Estado = New Estado()
        datos = Estado.BuscarDatos(conexion)
        Me.cboEstado.DataSource = datos.Tables(0)
        Me.cboEstado.DisplayMember = "descrip"
        Me.cboEstado.ValueMember = "idestado"

        Dim index As Integer = 0
        index = Me.cboEstado.FindString(Me.cboEstado.Text)
        Me.cboEstado.SelectedIndex = index

        cboEstado.Text = ""
    End Sub
    Private Sub ComboTipoTelefono()
        Dim datos As DataSet = Nothing
        TT = New TipoTelefono()
        datos = TT.BuscarDatos(conexion)
        Me.cboTipoTelP.DataSource = datos.Tables(0)
        Me.cboTipoTelP.DisplayMember = "Decrip"
        Me.cboTipoTelP.ValueMember = "IdTipoTel"

        Dim index As Integer = 0
        index = Me.cboTipoTelP.FindString(Me.cboTipoTelP.Text)
        Me.cboTipoTelP.SelectedIndex = index

        cboTipoTelP.Text = ""
    End Sub
    Private Sub frmActDatosPacienteCORREGIDO_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If bande = 50 Then
            cargarComboTipoDoc()
            cboTipoDoc.Text = TurnosCORREGIDO.cboTipo.Text
            txtNroDoc.Text = TurnosCORREGIDO.txtNroDoc.Text
            txtApe.Text = TurnosCORREGIDO.txtApe.Text
            txtNom.Text = TurnosCORREGIDO.txtNom.Text
            cmdNuevo.Visible = False
            cmdBuscar.Enabled = False
            cmdSelPac.Enabled = False

            cmdAgregar.Enabled = True
            cmdQuitar.Enabled = True
            cmdAceptar.Visible = True


            'ComboBarrio()
            ComboLoc()
            ComboObraSoc()
            ComboEstado()
            ComboTipoPac()
            ComboTipoTelefono()
            ban = 11

            fraObraSocial.Enabled = True

        Else
            cargarComboTipoDoc()
            LimpiarControles()
        End If


    End Sub

    Private Sub cmdSelPac_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSelPac.Click
        ban = 1

        Dim tipDoc As TipoDocumento = Nothing
        Dim barrio As Barrio = Nothing
        Dim frm As SelecPaciente = New SelecPaciente()
        frm.ShowDialog(Me)
        frm.Dispose()
        '   ban = 1

        cmdEliminar.Enabled = True
        cmdModi.Enabled = True
        cmdSelPac.Enabled = True
        cmdBuscar.Enabled = True
        cmdSalir.Enabled = True
        cmdCancelar.Enabled = True
        cmdNuevo.Visible = False

        With Me.Paciente
            txtApe.Text = .ApellidoPer
            txtNom.Text = .NombrePer
            txtNroDoc.Text = .NroDocumentoPer

            tipDoc = New TipoDocumento()
            If tipDoc.Buscar(.tipodocumentoPer, conexion) Then
                cboTipoDoc.Text = tipDoc.Descripcion
            End If

            txtCalle.Text = .CallePer
            txtNro.Text = .NroCallePer
            txtDpto.Text = .DptoPer
            txtPiso.Text = .PisoPer
            cboBarrio.Text = .Barrio.Descripcion
            cboLoc.Text = .Barrio.Localidad.Descripcion
            txtEmail.Text = .EmailPer
            cboTipoPac.Text = .TipoPaciente.Descripcion
            cboEstado.Text = .EstadoPac.Descripcion
            dtpFecNac.Value = .FecNacPer

            If cboTipoPac.Text <> "Particular" And cboTipoPac.Text <> "Derivante" Then
                fraObraSocial.Enabled = True
                cboObraSoc.Text = .ObraSocialP.DescripOS
                cboPlan.Text = .NomPlanPac
                txtNroAfiliado.Text = .NroAfiliadoP
            Else
                If cboTipoPac.Text = "Derivante" Then
                    txtObserv.Enabled = True
                    lblObserv.Enabled = True
                    txtObserv.Text = .ObsPac
                End If
            End If

            Me.grTelefonos.DataSource = .Telefonos(conexion)
            Me.grTelefonos.DataMember = "telefonos"

        End With

    End Sub
    Private Sub cmdSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSalir.Click
        Close()
    End Sub
    Private Sub LimpiarControles()
        cboTipoDoc.Text = ""
        txtNroDoc.Text = ""
        txtApe.Text = ""
        txtNom.Text = ""
        txtCalle.Text = ""
        txtNro.Text = ""
        txtPiso.Text = ""
        txtDpto.Text = ""
        cboLoc.Text = ""
        cboBarrio.Text = ""
        txtEmail.Text = ""
        cboTipoPac.Text = ""
        cboEstado.Text = ""
        cboObraSoc.Text = ""
        txtNroAfiliado.Text = ""
        cboPlan.Text = ""
        cboTipoTelP.Text = ""
    End Sub

    Private Sub cmdCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancelar.Click
        If MsgBox("Se perderan los cambios realizados, Desea continuar?", MsgBoxStyle.Information + MsgBoxStyle.OkCancel, "Atencion!") = MsgBoxResult.Ok Then
            LimpiarControles()
            cmdAceptar.Visible = False
            cmdModi.Enabled = False
            cmdEliminar.Enabled = False
            cmdNuevo.Visible = True
            cmdCancelar.Enabled = False
            cmdRegTel.Visible = False
            cmdAgregar.Visible = True
            lblTipoTel.Visible = False
            cboTipoTelP.Visible = False
            lblNroTelP.Visible = False
            txtNroTelP.Visible = False
            LimpiarGrillaTel()
            cmdBuscar.Enabled = True
            cmdSelPac.Enabled = True
        Else
            Exit Sub
            cmdBuscar.Enabled = True
            cmdSelPac.Enabled = True
        End If
    End Sub
    Private Sub RegistrarPac()
        Dim objPacNuevo As Paciente = New Paciente()
        Dim idTD As Integer = 0

        If cboTipoDoc.Text = "DNI" Then
            idTD = 1
        End If
        If cboTipoDoc.Text = "LC" Then
            idTD = 2
        End If
        If cboTipoDoc.Text = "CI" Then
            idTD = 3
        End If
        If cboTipoDoc.Text = "LE" Then
            idTD = 4
        End If
        If cboTipoDoc.Text = "MAT.PROF" Then
            idTD = 5
        End If

        'BARRIO
        Dim Barrio As Barrio = Nothing
        Barrio = New Barrio()
        DescBar = cboBarrio.Text
        With Me.Barrio
            If Barrio.BuscarId(DescBar, conexion) Then
                IdBar = Barrio.Identificado
            End If
        End With
        'ESTADO
        Dim Estado As Estado = Nothing
        Estado = New Estado()
        DescEst = cboEstado.Text
        With Me.Estado
            If Estado.BuscarId(DescEst, conexion) Then
                IdEst = Estado.identificador
            End If
        End With
        'OBRA SOCIAL
        Dim OS As ObraSocial = Nothing
        OS = New ObraSocial()
        DescOS = cboObraSoc.Text
        With Me.OS
            If OS.BuscarId(DescOS, conexion) Then
                IdObraSoc = OS.IdOS
            End If
        End With
        'TIPO PACIENTE
        Dim TPac As TipoPaciente = Nothing
        TPac = New TipoPaciente()
        DescTPac = cboTipoPac.Text
        With Me.TPac
            If TPac.BuscarId(DescTPac, conexion) Then
                IdTipoPac = TPac.Identificador
            End If
        End With

        objPacNuevo.idDoc = idTD
        objPacNuevo.NroDocumentoPer = txtNroDoc.Text
        objPacNuevo.ApellidoPer = txtApe.Text
        objPacNuevo.NombrePer = txtNom.Text
        objPacNuevo.CallePer = txtCalle.Text
        objPacNuevo.NroCallePer = Integer.Parse(txtNro.Text)

        If txtPiso.Text <> "" Then
            objPacNuevo.PisoPer = txtPiso.Text
        Else
            objPacNuevo.PisoPer = "-"
        End If
        If txtDpto.Text <> "" Then
            objPacNuevo.DptoPer = txtDpto.Text
        Else
            objPacNuevo.DptoPer = "-"
        End If

        objPacNuevo.IdBarrioPer = IdBar
        If txtEmail.Text <> "" Then
            objPacNuevo.EmailPer = txtEmail.Text
        Else
            objPacNuevo.EmailPer = "-"
        End If
        objPacNuevo.IdEstPac = IdEst
        objPacNuevo.idTipoPac = IdTipoPac

        If cboTipoPac.Text = "Afiliado" Then
            objPacNuevo.IDOSOCpac = IdObraSoc
            objPacNuevo.NomPlanPac = cboPlan.Text
            objPacNuevo.NroAfiliadoP = txtNroAfiliado.Text
        Else
            objPacNuevo.IDOSOCpac = 0
            objPacNuevo.NomPlanPac = "-"
            objPacNuevo.NroAfiliadoP = "-"
        End If
        objPacNuevo.FecNacPer = dtpFecNac.Value
        'Busco PK duplicada
        If objPacNuevo.validarPK(objPacNuevo.tipodocumentoPer, objPacNuevo.NroDocumentoPer, conexion) > 0 Then
            MsgBox("El turno ya ha sido asignado", MsgBoxStyle.Information, "Atencion!")
            Exit Sub
        End If
        If cboTipoPac.Text = "Derivante" Then
            If txtObserv.Text <> "" Then
                objPacNuevo.Agregar(conexion)
                LimpiarControles()
            Else
                MsgBox("Debe Completar los datos de Apellido y Nombre del paciente que fue derivado")
                txtObserv.Focus()
            End If
        Else
            objPacNuevo.Agregar(conexion)
            If bande = 50 Then
                TurnosCORREGIDO.cboTipo.Text = cboTipoDoc.Text
                TurnosCORREGIDO.txtNroDoc.Text = txtNroDoc.Text
                TurnosCORREGIDO.txtApe.Text = txtApe.Text
                TurnosCORREGIDO.txtNom.Text = txtNom.Text
                TurnosCORREGIDO.txtTipoPac.Text = cboTipoPac.Text
                TurnosCORREGIDO.txtNomOS.Text = cboObraSoc.Text
                TurnosCORREGIDO.txtPlan.Text = cboPlan.Text
                TurnosCORREGIDO.txtNroAfiliado.Text = txtNroAfiliado.Text
                Close()
            Else

            End If
            LimpiarControles()
            End If

    End Sub
    Private Sub cmdAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAceptar.Click
        If ban = 10 Then
            RegModi()
            cboTipoTelP.Visible = False
            lblTipoTel.Visible = False
            lblNroTel.Visible = False
            txtNroTelP.Visible = False
        Else
            RegistrarPac()
            cmdNuevo.Visible = True

        End If
    End Sub
    Private Sub cmdBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBuscar.Click
        cmdEliminar.Enabled = True
        cmdModi.Enabled = True
        cmdSelPac.Enabled = True
        cmdBuscar.Enabled = True
        cmdSalir.Enabled = True

        cmdNuevo.Visible = False

        Dim objPacBuscado As Paciente = New Paciente()


        Dim id As Integer = 0
        Dim numDoc As String = ""

        If cboTipoDoc.Text = "DNI" Then
            id = 1
        End If
        If cboTipoDoc.Text = "LC" Then
            id = 2
        End If
        If cboTipoDoc.Text = "CI" Then
            id = 3
        End If
        If cboTipoDoc.Text = "LE" Then
            id = 4
        End If
        If cboTipoDoc.Text = "MAT.PROF" Then
            idTD = 5
        End If

        numDoc = txtNroDoc.Text

        If objPacBuscado.Buscar(id, numDoc, conexion) Then
            txtApe.Text = objPacBuscado.ApellidoPer
            txtNom.Text = objPacBuscado.NombrePer
            txtCalle.Text = objPacBuscado.CallePer
            txtNro.Text = objPacBuscado.NroCallePer
            txtDpto.Text = objPacBuscado.DptoPer
            txtPiso.Text = objPacBuscado.PisoPer

            cboBarrio.Text = objPacBuscado.Barrio.Descripcion
            cboLoc.Text = objPacBuscado.Barrio.Localidad.Descripcion
            txtEmail.Text = objPacBuscado.EmailPer
            cboTipoPac.Text = objPacBuscado.TipoPaciente.Descripcion
            cboEstado.Text = objPacBuscado.EstadoPac.Descripcion
            dtpFecNac.Value = objPacBuscado.FecNacPer

            If cboTipoPac.Text <> "Particular" And cboTipoPac.Text <> "Derivante" Then
                fraObraSocial.Enabled = True
                cboObraSoc.Text = objPacBuscado.ObraSocialP.DescripOS
                cboPlan.Text = objPacBuscado.NomPlanPac
                txtNroAfiliado.Text = objPacBuscado.NroAfiliadoP
            Else
                If cboTipoPac.Text = "Derivante" Then
                    txtObserv.Enabled = True
                    lblObserv.Enabled = True
                End If

            End If

            Me.grTelefonos.DataSource = objPacBuscado.Telefonos(conexion)
            Me.grTelefonos.DataMember = "telefonos"
        End If

    End Sub
    Private Sub cmdAgregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAgregar.Click
        lblTipoTel.Visible = True
        lblNroTelP.Visible = True
        cboTipoTelP.Visible = True
        txtNroTelP.Visible = True
        cmdAgregar.Visible = False
        cmdRegTel.Visible = True
        ComboTipoTelefono()
    End Sub
    Private Sub cmdRegTel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRegTel.Click
        Dim objTelNuevo As Paciente = New Paciente()
        Dim paci As Paciente = New Paciente()
        Dim id As Integer = 0
        Dim numDoc As String = ""

        If cboTipoDoc.Text = "DNI" Then
            id = 1
        End If
        If cboTipoDoc.Text = "LC" Then
            id = 2
        End If
        If cboTipoDoc.Text = "CI" Then
            id = 3
        End If
        If cboTipoDoc.Text = "LE" Then
            id = 4
        End If
        If cboTipoDoc.Text = "MAT.PROF" Then
            idTD = 5
        End If

        numDoc = txtNroDoc.Text
        Dim TipoTel As TipoTelefono = Nothing
        TipoTel = New TipoTelefono()
        DescTT = cboTipoTelP.Text
        With Me.TipoTel
            If TipoTel.BuscarId(DescTT, conexion) Then
                IdTipoTel = TipoTel.TipoTelefono
            End If
        End With
        objTelNuevo.idDoc = id
        objTelNuevo.NroDocumentoPer = txtNroDoc.Text
        objTelNuevo.TipoTel = IdTipoTel
        objTelNuevo.NroTelefono = txtNroTelP.Text

        objTelNuevo.AgregarTel(conexion)
        cboTipoTelP.Text = ""
        txtNroTelP.Text = ""
        'LimpiarGrillaTel()
        'With Me.paci
        Me.grTelefonos.DataSource = paci.Telefonos(conexion)
        Me.grTelefonos.DataMember = "telefonos"
        'End With

    End Sub

    Private Sub grTelefonos_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grTelefonos.CellContentClick
        If grTelefonos.Columns(e.ColumnIndex).Name = "colCheck" Then
            
            Dim celda As DataGridViewButtonCell = _
                CType(Me.grTelefonos.Rows(e.RowIndex).Cells("colCheck"), DataGridViewButtonCell)

            cboTipoTelP.Text = grTelefonos.Rows(e.RowIndex).Cells("TipoTel").Value
            txtNroTelP.Text = grTelefonos.Rows(e.RowIndex).Cells("numero").Value

        End If
    End Sub

    Private Sub LimpiarGrillaTel()
        'PRUEBA DE LIMPIAR GRILLA

        Dim dt As DataSet
        Dim dt2 As DataSet

        grTelefonos.Columns.Clear()

        dt = Paciente.Telefonos(conexion)
        dt2 = dt.Clone
        grTelefonos.DataSource = dt2
    End Sub

    Private Sub cmdQuitar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdQuitar.Click
        '****BORRO LA FILA SELECCIONADA EN EL DataGridView
        If MsgBox("Esta seguro que desea ELIMINAR DATOS DEL PACIENTE? ", vbYesNo + vbQuestion) = vbYes Then
            Dim objEliminar As Paciente = Nothing
            objEliminar = New Paciente()
            Me.grTelefonos.Rows.Remove(Me.grTelefonos.CurrentRow)

            Dim id As Integer = 0
            Dim numDoc As String = ""
            Dim idtipotel As Integer = 0
            Dim numtel As String = ""
            'TIPO DOCUMENTO
            If cboTipoDoc.Text = "DNI" Then
                id = 1
            End If
            If cboTipoDoc.Text = "LC" Then
                id = 2
            End If
            If cboTipoDoc.Text = "CI" Then
                id = 3
            End If
            If cboTipoDoc.Text = "LE" Then
                id = 4
            End If
            If cboTipoDoc.Text = "MAT.PROF" Then
                idTD = 5
            End If

            'TIPO TELEFONO
            If cboTipoTelP.Text = "PARTICULAR FIJO" Then
                idtipotel = 1
            End If
            If cboTipoTelP.Text = "CELULAR" Then
                idtipotel = 2
            End If
            If cboTipoTelP.Text = "LABORAL" Then
                idtipotel = 3
            End If

            numDoc = txtNroDoc.Text
            numtel = txtNroTelP.Text

            With Me.Paciente
                objEliminar.EliminarTelefonos(id, numDoc, idtipotel, numtel, conexion)
            End With
        End If

    End Sub

    Private Sub cmdEliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEliminar.Click


        If MsgBox("Esta seguro que desea ELIMINAR DATOS DEL PACIENTE? ", vbYesNo + vbQuestion) = vbYes Then
            Dim objEliminar As Paciente = Nothing
            objEliminar = New Paciente()

            Dim id As Integer = 0
            Dim numDoc As String = ""

            If cboTipoDoc.Text = "DNI" Then
                id = 1
            End If
            If cboTipoDoc.Text = "LC" Then
                id = 2
            End If
            If cboTipoDoc.Text = "CI" Then
                id = 3
            End If
            If cboTipoDoc.Text = "LE" Then
                id = 4
            End If
            If cboTipoDoc.Text = "MAT.PROF" Then
                idTD = 5
            End If

            numDoc = txtNroDoc.Text
            With Me.Paciente
                objEliminar.Eliminar(id, numDoc, conexion)
            End With
        End If
    End Sub
    Private Sub RegModi()
        Dim objPacModi As Paciente = New Paciente()
        Dim id As Integer = 0
        Dim numDoc As String = ""

        If cboTipoDoc.Text = "DNI" Then
            id = 1
        End If
        If cboTipoDoc.Text = "LC" Then
            id = 2
        End If
        If cboTipoDoc.Text = "CI" Then
            id = 3
        End If
        If cboTipoDoc.Text = "LE" Then
            id = 4
        End If
        If cboTipoDoc.Text = "MAT.PROF" Then
            idTD = 5
        End If

        numDoc = txtNroDoc.Text

        'BARRIO
        Dim Barrio As Barrio = Nothing
        Barrio = New Barrio()
        DescBar = cboBarrio.Text
        With Me.Barrio
            If Barrio.BuscarId(DescBar, conexion) Then
                IdBar = Barrio.Identificado
            End If
        End With
        'ESTADO
        Dim Estado As Estado = Nothing
        Estado = New Estado()
        DescEst = cboEstado.Text
        With Me.Estado
            If Estado.BuscarId(DescEst, conexion) Then
                IdEst = Estado.identificador
            End If
        End With
        'OBRA SOCIAL
        Dim OS As ObraSocial = Nothing
        OS = New ObraSocial()
        DescOS = cboObraSoc.Text
        With Me.OS
            If OS.BuscarId(DescOS, conexion) Then
                IdObraSoc = OS.IdOS
            End If
        End With
        'TIPO PACIENTE
        Dim TPac As TipoPaciente = Nothing
        TPac = New TipoPaciente()
        DescTPac = cboTipoPac.Text
        With Me.TPac
            If TPac.BuscarId(DescTPac, conexion) Then
                IdTipoPac = TPac.Identificador
            End If
        End With

        objPacModi.idDoc = id
        objPacModi.NroDocumentoPer = numDoc
        objPacModi.ApellidoPer = txtApe.Text
        objPacModi.NombrePer = txtNom.Text
        objPacModi.CallePer = txtCalle.Text
        objPacModi.NroCallePer = Integer.Parse(txtNro.Text)

        If txtPiso.Text <> "" Then
            objPacModi.PisoPer = txtPiso.Text
        Else
            objPacModi.PisoPer = "-"
        End If
        If txtDpto.Text <> "" Then
            objPacModi.DptoPer = txtDpto.Text
        Else
            objPacModi.DptoPer = "-"
        End If

        If txtObserv.Text <> "" Then
            objPacModi.ObsPac = txtObserv.Text
        Else
            objPacModi.ObsPac = "-"
        End If

        objPacModi.IdBarrioPer = IdBar
        If txtEmail.Text <> "" Then
            objPacModi.EmailPer = txtEmail.Text
        Else
            objPacModi.EmailPer = "-"
        End If
        objPacModi.IdEstPac = IdEst
        objPacModi.idTipoPac = IdTipoPac

        If cboTipoPac.Text = "Afiliado" Then
            objPacModi.IDOSOCpac = IdObraSoc
            objPacModi.NomPlanPac = cboPlan.Text
            objPacModi.NroAfiliadoP = txtNroAfiliado.Text
        Else
            objPacModi.IDOSOCpac = 0
            objPacModi.NomPlanPac = "-"
            objPacModi.NroAfiliadoP = "-"
        End If
        objPacModi.FecNacPer = dtpFecNac.Value

        With Me.Paciente
            objPacModi.Modificar(id, numDoc, conexion)
        End With

        LimpiarControles()
        LimpiarGrillaTel()
    End Sub
    
    Private Sub cmdModi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdModi.Click
        cmdCancelar.Enabled = True
        cmdSalir.Enabled = True

        cmdNuevo.Enabled = False
        cmdAceptar.Visible = True
        cmdAgregar.Enabled = True
        cmdQuitar.Enabled = True
        Dim td As String = ""
        Dim loc As String = ""
        Dim os As String = ""
        Dim est As String = ""
        Dim tp As String = ""
        td = cboTipoDoc.Text
        loc = cboLoc.Text
        os = cboObraSoc.Text
        est = cboEstado.Text
        tp = cboTipoPac.Text

        cargarComboTipoDoc()
        'ComboBarrio()
        ComboLoc()
        ComboObraSoc()
        ComboEstado()
        ComboTipoPac()
        ComboTipoTelefono()

        ban = 10

        cboTipoDoc.Text = td
        cboLoc.Text = loc
        cboObraSoc.Text = os
        cboEstado.Text = est
        cboTipoPac.Text = tp

        
    End Sub

    Private Sub cmdNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNuevo.Click
        cmdNuevo.Visible = False
        cmdAceptar.Visible = True

        cargarComboTipoDoc()
        ComboBarrio()
        ComboLoc()
        ComboObraSoc()
        ComboEstado()
        ComboTipoPac()
        ComboTipoTelefono()
        ban = 11
        LimpiarControles()
        fraObraSocial.Enabled = True
        cmdBuscar.Enabled = False
        cmdSelPac.Enabled = False
        fraObraSocial.Enabled = False
    End Sub

    'Private Sub cboTipoPac_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboTipoPac.Click
    '    'lblObserv.Enabled = True
    '    'txtObserv.Enabled = True
    '    'If cboTipoPac.Text = "Afiliado" Then
    '    '    fraObraSocial.Enabled = True
    '    'End If
    'End Sub
    Function SoloNumeros(ByVal Keyascii As Short) As Short
        If InStr("1234567890", Chr(Keyascii)) = 0 Then
            SoloNumeros = 0
        Else
            SoloNumeros = Keyascii
        End If
        Select Case Keyascii
            Case 8
                SoloNumeros = Keyascii
            Case 13
                SoloNumeros = Keyascii
        End Select
    End Function
    Private Sub txtNroDoc_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNroDoc.KeyPress
        Dim KeyAscii As Short = CShort(Asc(e.KeyChar))
        KeyAscii = CShort(SoloNumeros(KeyAscii))
        If KeyAscii = 0 Then
            e.Handled = True
        End If
    End Sub

    Private Sub txtNro_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNro.KeyPress
        Dim KeyAscii As Short = CShort(Asc(e.KeyChar))
        KeyAscii = CShort(SoloNumeros(KeyAscii))
        If KeyAscii = 0 Then
            e.Handled = True
        End If
    End Sub

    Private Sub txtNroAfiliado_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNroAfiliado.KeyPress
        Dim KeyAscii As Short = CShort(Asc(e.KeyChar))
        KeyAscii = CShort(SoloNumeros(KeyAscii))
        If KeyAscii = 0 Then
            e.Handled = True
        End If
    End Sub

    Private Sub cboLoc_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboLoc.SelectedIndexChanged
        ComboBarrio()
    End Sub

    Private Sub cboTipoPac_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboTipoPac.SelectedIndexChanged
        lblObserv.Enabled = True
        txtObserv.Enabled = True
        If cboTipoPac.Text = "Afiliado" Then
            fraObraSocial.Enabled = True
        End If
    End Sub
End Class